<?php
declare (strict_types=1);

namespace app\common\controller;

class BaseController extends \app\BaseController
{
    protected $validate = null;
    protected $request = null;
    protected $logic = null;

    public function initialize()
    {
        parent::initialize();
        $this->request = \think\facade\Request::instance();
        $name = app('http')->getName();
        $classPrefix = str_replace('.', '\\', $this->request->controller());
        if (!empty($classPrefix)) {
            $validateClass = '\app\\' . $name . '\validate\\' . $classPrefix . 'Validate';
            $logicClass = '\app\\' . $name . '\logic\\' . $classPrefix . 'Logic';

            // 判断是否存在验证类
            if (class_exists($validateClass)) {
                app($validateClass);
            }
            // 判断是否有服务类
            if (class_exists($logicClass)) {
                $this->logic = app($logicClass);
            }
        }
    }

    public function index()
    {
        return $this->logic->index($this->request);
    }

    public function create()
    {
        return $this->logic->create($this->request);
    }

    public function read($id)
    {
        return $this->logic->read($this->request, $id);
    }

    public function save()
    {
        return $this->logic->save($this->request);
    }

    public function edit($id)
    {
        return $this->logic->edit($this->request, $id);
    }

    public function update($id)
    {
        return $this->logic->update($this->request, $id);
    }

    public function renew($id)
    {
        return $this->logic->renew($this->request, $id);
    }

    public function delete($id)
    {
        return $this->logic->delete($this->request, $id);
    }

    public function status($id)
    {
        return $this->logic->status($this->request, $id);
    }

    public function sort($id)
    {
        return $this->logic->sort($this->request, $id);
    }

    public function export()
    {
        return $this->logic->export($this->request);
    }

    public function prints()
    {
        return $this->logic->prints($this->request);
    }

    public function feedback()
    {
        return $this->logic->feedback($this->request);
    }

    public function orderOperate()
    {
        return $this->logic->orderOperate($this->request);
    }

    public function evaluate()
    {
        return $this->logic->evaluate($this->request);
    }

    public function operate()
    {
        return $this->logic->operate($this->request);
    }

}